<?php
namespace App\Repositories\Api;

use  App\Models\Content;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

use Exception;

class ContentRepository
{
    public function getPages(array $filter = [], int $pageSize = 10, int $pageNum=1)
    {
        $res =  Content::where("status", "=", 2)
            ->when(intval($filter['type']), function($query) use ($filter){
                return $query->where("category_id", "=", intval($filter['type']));
            })
            ->orderBy('publish_time','desc')
            ->paginate($filter['limit']?$filter['limit']:$pageSize, ["id","thumb","summary","content","title"], null, $pageNum)
            ->toArray();

        $res = filterPaginateData($res);

        return $res;
    }

    public function getOne($id)
    {
        return Content::where("id","=", intval($id))->first();
    }

}